import { checkPhone, isNullPm } from './baseMethods';

/**
 *  针对一些常用的方法进行类定义,方便重构
 */
interface ISPARAMSTATE {
  state: boolean;
  value: any;
  index: any;
}
interface AQMSTEAM<T = any> {
  param: Array<T>;
  key: string;
  paramKey?: string | any;
}
/**
 * @class ArrayQueryMethod 数组查询方法体
 */
class ArrayQueryMethod {
  ArrayQueryMethod;
  constructor(steam: AQMSTEAM) {
    const state: ISPARAMSTATE = {
      state: false,
      value: '',
      index: null,
    };
    this.ArrayQueryMethod = steam.param.some((res: any, index): any => {
      if (isNullPm(steam.paramKey) ? res === steam.key : res[steam.paramKey] == steam.key) {
        state.state = true;
        state.value = res;
        state.index = index;
        return state;
      }
    });
  }
}

interface RBSTEAM {
  title: string;
  method: (steam: any) => any;
}
/**
 * @class RuleBody 默认表单规则体
 */
class RuleBody {
  RuleBody;
  constructor(steam: RBSTEAM) {
    this.RuleBody = {
      message: steam.title,
      validator: (val: string) => {
        return steam.method(val);
      },
    };
  }
}
export { ArrayQueryMethod, RuleBody, RBSTEAM };
